Skip to content

feat(analytics): 添加 Microsoft Clarity 分析脚本和通知 - #643

Merged
wess09 merged 1 commit into
masterfrom
dev
Jul 27, 2026
Merged

feat(analytics): 添加 Microsoft Clarity 分析脚本和通知#643
wess09 merged 1 commit into
masterfrom
dev

Conversation

@wess09

@wess09 wess09 commented Jul 27, 2026

Copy link
Copy Markdown
Owner

Summary by Sourcery

在 WebUI 主应用初始化中添加 Microsoft Clarity 分析集成。

新功能:

  • 显示一次性通知,告知用户 Microsoft Clarity 被用于收集交互和性能数据。
  • 将 Microsoft Clarity 跟踪脚本注入到 WebUI 中,确保在每个会话中只添加一次。
Original summary in English

Summary by Sourcery

Add Microsoft Clarity analytics integration to the WebUI home application initialization.

New Features:

  • Display a one-time notification informing users that Microsoft Clarity is used to collect interaction and performance data.
  • Inject the Microsoft Clarity tracking script into the WebUI, ensuring it is added only once per session.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@sourcery-ai

sourcery-ai Bot commented Jul 27, 2026

Copy link
Copy Markdown
审阅者指南(在小型 PR 中折叠)

审阅者指南

向 WebUI home 应用添加 Microsoft Clarity 分析脚本,并显示一次性通知 Toast,告知用户有关数据收集的信息。

WebUI home 中 Microsoft Clarity 注入与通知的时序图

sequenceDiagram
    actor User
    participant Browser
    participant AppHome

    User->>Browser: Open WebUI home
    Browser->>AppHome: run(initial_page)
    AppHome->>Browser: set_env(title, output_animation)
    AppHome->>Browser: get_localstorage(clarity_notice_shown)
    alt [clarity_notice_shown != 1]
        AppHome->>Browser: set_localstorage(clarity_notice_shown, 1)
        AppHome->>Browser: toast(message, color, duration)
    end
    AppHome->>Browser: run_js(load_clarity_script)
    AppHome->>Browser: run_js(append_manifest_link)
Loading

文件级变更

变更 详情 文件
在 WebUI 启动时注入 Microsoft Clarity 分析,并显示一次性数据收集通知。
  • 检查本地存储标记,以确定当前浏览器中是否已显示过 Clarity 通知,并在首次显示后进行设置。
  • 显示信息性 Toast,说明 Microsoft Clarity 收集哪些分析数据以及原因。
  • 通过 run_js 注入 Microsoft Clarity 跟踪脚本,并通过脚本元素 ID 检查进行保护,确保在每个会话中最多只添加一次该脚本。
  • 保持现有的 manifest 链接注入逻辑不变,并在分析初始化之后执行。
module/webui/app_home.py

技巧与命令

与 Sourcery 交互

  • 触发新的审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复审查评论,请求 Sourcery 从该评论创建一个 issue。你也可以回复审查评论 @sourcery-ai issue 来从该评论创建一个 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在你想要的位置随时生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可随时(重新)生成审阅者指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已经处理完所有评论且不想再看到它们,这会很有用。
  • 取消所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,即可取消所有现有的 Sourcery 审查。若你想在一个新的审查中重新开始,这特别有用——别忘了评论 @sourcery-ai review 来触发新的审查!

自定义你的使用体验

访问你的 控制面板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审阅者指南等。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a Microsoft Clarity analytics script to the WebUI home app and shows a one-time notification toast informing users about data collection.

Sequence diagram for Microsoft Clarity injection and notice in WebUI home

sequenceDiagram
    actor User
    participant Browser
    participant AppHome

    User->>Browser: Open WebUI home
    Browser->>AppHome: run(initial_page)
    AppHome->>Browser: set_env(title, output_animation)
    AppHome->>Browser: get_localstorage(clarity_notice_shown)
    alt [clarity_notice_shown != 1]
        AppHome->>Browser: set_localstorage(clarity_notice_shown, 1)
        AppHome->>Browser: toast(message, color, duration)
    end
    AppHome->>Browser: run_js(load_clarity_script)
    AppHome->>Browser: run_js(append_manifest_link)
Loading

File-Level Changes

Change Details Files
Inject Microsoft Clarity analytics and show a one-time data collection notice when the WebUI starts.
  • Check local storage flag to determine if the Clarity notice has been shown in the current browser and set it after first display.
  • Display an informational toast describing what analytics data Microsoft Clarity collects and why.
  • Inject the Microsoft Clarity tracking script via run_js, guarding with a script element ID check so the script is added at most once per session.
  • Keep the existing manifest link injection logic unchanged and executed after the analytics initialization.
module/webui/app_home.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@wess09
wess09 merged commit f91e155 into master Jul 27, 2026
9 checks passed

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗨,我在下面给出了一些总体反馈:

  • 建议将 Microsoft Clarity 的项目 ID 以及启用/禁用开关做成可配置项(例如通过设置或环境变量),而不是在 run_js 调用中直接硬编码 'xszl2nrp3q'
  • run_js 中那段很长的内联 JavaScript 字符串比较难读也不易维护;可以考虑把它抽取到一个辅助函数中,或者使用多行模板来提升可读性并降低语法问题的风险。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- Consider making the Microsoft Clarity project ID and enable/disable flag configurable (e.g., via settings or environment variables) instead of hardcoding `'xszl2nrp3q'` directly in the `run_js` call.
- The long inline JavaScript string in `run_js` is hard to read and maintain; consider extracting it into a helper function or using a multi-line template to improve readability and reduce the risk of syntax issues.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请对每条评论点 👍 或 👎,我会根据你的反馈持续改进评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • Consider making the Microsoft Clarity project ID and enable/disable flag configurable (e.g., via settings or environment variables) instead of hardcoding 'xszl2nrp3q' directly in the run_js call.
  • The long inline JavaScript string in run_js is hard to read and maintain; consider extracting it into a helper function or using a multi-line template to improve readability and reduce the risk of syntax issues.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider making the Microsoft Clarity project ID and enable/disable flag configurable (e.g., via settings or environment variables) instead of hardcoding `'xszl2nrp3q'` directly in the `run_js` call.
- The long inline JavaScript string in `run_js` is hard to read and maintain; consider extracting it into a helper function or using a multi-line template to improve readability and reduce the risk of syntax issues.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant